/*
 * Key.c
 *
 *  Created on: 09-02-2012
 *      Author: Mati
 */
#include "Key.h"

/*------------------------------------------------------------------------------
  configer Button pins
 *------------------------------------------------------------------------------*/
__INLINE void Key_Config(void) {

	LPC_SC->PCONP |= (1 << 15);								// turn ON GPIO
	LPC_GPIO2->FIOMASK &= ~((1<<10)|(1<<11)|(1<<12));				// Int0 - p2.10, key1 - P2.11 i key2 - P2.22
	LPC_GPIO2->FIODIR  &= ~((1<<10)|(1<<11)|(1<<12));				// P2.10, P2.11 i P2.22 jako wejscie
	//LPC_GPIO2->FIOPIN  |=  0x00000400;
	//LPC_GPIOINT->IO2IntEnR |= (1 << 10);			// Int0, ( (1 << 11) | (1<<12) );
	//NVIC_EnableIRQ(EINT3_IRQn);
	LPC_PINCON->PINSEL4 |= (1U<<20);				//P2.10 jest EINT0
}

/*------------------------------------------------------------------------------
  Read Buttons
 *------------------------------------------------------------------------------*/
int Key_Status(uint32_t key){

  if (( ( (LPC_GPIO2->FIOPIN)&(1<<key) )>>key ) == 0) {     // 0 - Key On
	  return 0;
  }
  else {
	  return 1;
  }
}

/*------------------------------------------------------------------------------
  EINT3 Handler
 *------------------------------------------------------------------------------*/
/*void EINT3_IRQHandler(void)
{
	UART_PrintStr("EINT3\n");
  if ((LPC_GPIOINT->IO2IntStatR & (1 << 11)) == (1 << 11))
  {
  //raising edge interrupt on pin 0.3 was fired
  LPC_GPIOINT->IO2IntClr |= (1 << 11); // clear the status
  //do your task
  LED_On(1<<7);
  LED_Off(1<<0);
  return;
  }

  if ((LPC_GPIOINT->IO2IntStatR & (1 << 12)) == (1 << 12))
  {
  //raising edge interrupt on pin 0.5 was fired
  LPC_GPIOINT->IO2IntClr |= (1 << 12); // clear the status
  //do your task
  LED_On(1<<0);
  LED_Off(1<<7);
  return;
  }
}*/

void EINT3_IRQHandler(void){
	LPC_GPIOINT->IO2IntClr |= (1 << 10);

	//UART_PrintStr("INT0");
	LED_Toggle(1<<6);
}


